/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2022-01-30 07:57:53
 * @LastEditors: GGB
 * @LastEditTime: 2022-01-30 08:05:07
 */

// 核心
import {
    useEffect
} from 'react'
  
const { ipcRenderer } = window.require('electron')
const useIpcRenderer = (keyCallbackMap) => { 
    useEffect(() => { 
        Object.keys(keyCallbackMap).forEach(key => { 
            ipcRenderer.on(key, keyCallbackMap[key])
        })
        return () => { 
            Object.keys(keyCallbackMap).forEach(key => { 
                ipcRenderer.removeListener(key, keyCallbackMap[key])
            })
        }
      })
}

export default useIpcRenderer